"""
@author: chy
@file: tree命令.py
@time: 2023/11/28 20:03
"""
import os


def tree_ord(dir, depth):
    # 如果是母文件，则不用缩进和连接符直接输出
    if depth == 0:
        print(dir)
    for element in os.listdir(dir):
        # 输出子文件夹
        print(" |     " * depth, "|----" + element)
        # 更新到子文件夹的路径
        path = dir + "//" + element
        # 判断子文件夹是否为文件夹
        if (os.path.isdir(path)):
            # 如果是文件夹则递归输出,深度+1
            tree_ord(path, depth + 1)

Dir = input("请输入要查询的文件夹路径,如D:\\三创\开发\pycharm：\n")
tree_ord(Dir, 0)